package com.alg.test.excep;

/**
 * @author Li
 * @Date 2023/4/19 16:30
 */
public class ExceptionDemo2 {
    public static void main(String[] args) {
        int[] array = null;
        print(array);
     try {
         print(array);
     }catch (NullPointerException e){
         System.out.println("处理异常");
     }
        System.out.println("买买买！");
    }

    private static void print(int[] array) {
        if (array==null){
         throw new NullPointerException();
        }else {
            for (int i = 0; i < array.length; i++) {
                System.out.println(array[i]);
            }
        }
    }
}
